﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Actuant.Utility
{
    public class DateTimeUtility
    {
        public enum DateTimeCompare
        {
            Year = 0,
            Month,
            Day,
            Hour,
            Minute,
            Second
        }

        public static int DateDiff(DateTimeCompare howToCompare, DateTime startDate, DateTime endDate)
        {
            int diff = 0;
            TimeSpan ts = new TimeSpan(endDate.Ticks - startDate.Ticks);

            switch (howToCompare)
            {
                case DateTimeCompare.Year:
                    diff = Convert.ToInt32(ts.TotalDays / 365);
                    break;
                case DateTimeCompare.Month:
                    diff = Convert.ToInt32((ts.TotalDays / 365) * 12);
                    break;
                case DateTimeCompare.Day:
                    diff = Convert.ToInt32(ts.TotalDays);
                    break;
                case DateTimeCompare.Hour:
                    diff = Convert.ToInt32(ts.TotalHours);
                    break;
                case DateTimeCompare.Minute:
                    diff = Convert.ToInt32(ts.TotalMinutes);
                    break;
                case DateTimeCompare.Second:
                    diff = Convert.ToInt32(ts.TotalSeconds);
                    break;
                default:
                    break;
            }

            return diff;
        }
    }
}
